﻿using LyyCore.Configuration;
using LyyCore.Web;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;

namespace LyyCore.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class LyyCoreDbContextFactory : IDesignTimeDbContextFactory<LyyCoreDbContext>
    {
        public LyyCoreDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<LyyCoreDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            LyyCoreDbContextConfigurer.Configure(builder, configuration.GetConnectionString(LyyCoreConsts.ConnectionStringName));

            return new LyyCoreDbContext(builder.Options);
        }
    }
}